var window = window;

var core =
{
	dom:
	{
		get create() {},

		get zIndexMax()
		{
			var elements = core.window.document.getElementsByTagName('*');
			var zIndex, zIndexMax = 0;
			for(var i = 0; i < elements.length; i++)
			{
				zIndex = core.window.document.defaultView.getComputedStyle(elements[i], null).getPropertyValue('z-index');
				zIndexMax = ((zIndex != 'auto') && (zIndex > zIndexMax)) ? zIndex : zIndexMax;
			}
			return zIndexMax;
		},

		hide: function(className, id)
		{
			var obj = core.window.document.getElementById(className + id);
			obj.style.display = 'none';
		},

		move: function(className, id, x, y)
		{
			var obj = core.window.document.getElementById(className + id);
			obj.style.left = x + 'px';
			obj.style.top = y + 'px';
		},

		resize: function(className, id, width, height)
		{
			var obj = core.window.document.getElementById(className + id);
			obj.style.height = height + 'px';
			obj.style.width = width + 'px';
		},

		set create(element)
		{
			var obj = core.window.document.createElement(element.type);
			/* main */
			obj.className = element.className;
			obj.id = element.id;
			
			/* events */
			obj.onclick = (element.onclick !== undefined) ? element.onclick : obj.onclick;
			obj.onmouseout = (element.onmouseout !== undefined) ? element.onmouseout : obj.onmouseout;
			obj.onmouseover = (element.onmouseover !== undefined) ? element.onmouseover : obj.onmouseover;

			/* view */
			obj.style.display = (element.display !== undefined) ? element.display : obj.style.display;
			obj.style.height = (element.height !== undefined) ? element.height : obj.style.height;
			obj.style.left = element.x;
			obj.style.top = element.y;
			obj.style.width = (element.width !== undefined) ? element.width : obj.style.width;
			obj.style.zIndex = (element.zIndex !== undefined) ? element.zIndex : obj.style.zIndex;

			element.parent.appendChild(obj, element.parent);
		},

		show: function(className, id)
		{
			var obj = core.window.document.getElementById(className + id);
			obj.style.display = 'block';
		},

		style: function(className, id, style)
		{
			var obj = core.window.document.getElementById(className + id);
			obj.className = style;
		},

		zIndex:
		{
			down: function()
			{
				if(core.dom.zIndex.obj !== undefined)
				{
					core.dom.zIndex.obj.style.zIndex = core.dom.zIndex.value;
				}
			},

			obj: undefined,

			up: function(className, id)
			{
				core.dom.zIndex.obj = core.window.document.getElementById(className + id);
				core.dom.zIndex.value = core.dom.zIndex.obj.style.zIndex;
				core.dom.zIndex.obj.style.zIndex++;
			},

			value: 0
		}
	},

	get log() {},

	Note: function(note)
	{
		this.id = note.id;
		this.x = note.x;
		this.y = note.y;
	},

	note:
	{
		create: function(x, y)
		{
			var id = core.notes.length;
			var minSize = 16;

			core.notes[id] = new core.Note
			(
				{
					id: id,
					x: x,
					y: y
				}
			);

			/* noteContent */
			core.dom.create =
			{
				className: 'noteContent',
				id: 'noteContent' + id,

				onclick: function()
				{
					core.dom.show('noteTextarea', id);
					core.dom.style('noteContent', id, 'noteContentEdit');
					core.dom.zIndex.down();
					core.dom.zIndex.up('noteContent', id);
				},

				onmouseout: function()
				{
					core.note.isMouseOver = false;
				},

				onmouseover: function()
				{
					core.note.isMouseOver = true;
				},

				parent: core.window.document.body,
				type: 'div',
				x: parseInt(x - minSize/2) + 'px',
				y: parseInt(y - minSize/2) + 'px',
				zIndex: core.dom.zIndexMax
			};

			/* noteTextarea */
			core.dom.create =
			{
				className: 'noteTextarea',
				id: 'noteTextarea' + id,
				onmouseout: function()
				{
					
				},
				parent: core.window.document.getElementById('noteContent' + id),
				type: 'textarea',
				x: 0,
				y: 0
			};
		},

		isMouseOver: false,

		show: function()
		{
			core.dom.show('noteContent', core.notes.length - 1);
		},

		x: 0,
		y: 0
	},

	notes: [],

	set log(message)
	{
		core.window.console.log(message);
	},

	window : window
};
